package com.marvels.loanapply.customerservice.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.loanapply.customerservice.dto.CustomerServiceDTO;
import com.marvels.loanapply.customerservice.service.ICustomerService;
import com.marvels.loanapply.dto.CollectAccountDTO;
import com.marvels.loanapply.dto.CommonConditionDTO;
import com.marvels.loanapply.dto.McfeCustomerRepaymentPlanDTO;

/**
 * 客服查询控制层
 * @author zhaosa
 *
 */
@RestController
@RequestMapping("/loanapply/customerservice/query/service")
public class CustomerServiceQueryServiceContoller {
	
	@Autowired
	private ICustomerService customerService;
	/**
	 * 客服列表查询
	 * @param customerDto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("findPageList")
	@ResponseBody
	public MarvelsResultDTO findPageList(@RequestBody CustomerServiceDTO customerDto) throws MarvelsBusinessException{
		Map<String, Object> pageInfo = null;
		try {
			pageInfo = customerService.findPageList(customerDto);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("客服查询分页查询异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), pageInfo);
	}
	/**
	 * 查询绑定银行卡信息
	 * @param customerDto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("findBankCardPageList")
	@ResponseBody
	public MarvelsResultDTO findBankCardPageList(@RequestBody CustomerServiceDTO customerDto)throws MarvelsBusinessException{
		List<CustomerServiceDTO> pageInfo = null;
		try {
			pageInfo = customerService.findBankCardPageList(customerDto);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("客服查询分页查询银行卡绑卡信息异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), pageInfo);
	}
	/**
	 * 分页查询还款计划信息
	 * @param customerDto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("findPlanList")
	@ResponseBody
	public MarvelsResultDTO findPlanList(@RequestBody CommonConditionDTO dto)throws MarvelsBusinessException{
		PageInfo<McfeCustomerRepaymentPlanDTO> pageInfo = null;
		try {
			pageInfo = customerService.findPlanList(dto);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("客服查询分页还款计划异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), pageInfo);
	}
	/**
	 * 查询贷款合同信息
	 * @param customerDto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("findLoanContractInfo")
	@ResponseBody
	public MarvelsResultDTO findLoanContractInfo(@RequestBody CommonConditionDTO dto)throws MarvelsBusinessException{
		CollectAccountDTO loanContractInfo = null;
		try {
			loanContractInfo = customerService.selectAccountInfo(dto.getLoanId());
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("客服查询分页还款计划异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), loanContractInfo);
	}
	
}
